import {openWeb, windowOpen} from "@/common/common";
import videoTtv from "../component/videoTtv";
import allVideo from "../component/allVideo";
import articleDetail from "../component/articleDetail";
import allArticle from "../component/allArticle";
import msg from "../component/msg";

const mixin = {
	methods: {
		//刷新页面
		onRefresh() {
			window.location.reload();
		},
		//点击直播
		onLive(item) {
			let url = '';
			if (/inmuu/g.test(item.liveLink)) {
				url = item.liveLink;
			} else {
				let token = localStorage.getItem('token') || '';
				url = item.liveLink + '&token=' + token;
			}
			
			if (item.liveLink) {
				windowOpen(url);
			} else {
				this.$layer.iframe({
					content: {
						content: liveDetail, //传递的组件对象
						parent: this,//当前的vue对象
						data: {
							channelId: item.channelId,
							channelName: item.channelName,
							configId: item.configId
						}//props
					},
					area: ['900px', '650px'],
					title: item.channelName,
					maxmin: true,
					shade: true,
				});
			}
		},
		//点击文章分类
		onArticleGroup(item) {
			
			let address = this.urlAbsolute(`/experience/index.html#/allArticle?articleType=${item.articleType}`)
			
			openWeb(address,item.title,1);
			return;
			
			this.$layer.iframe({
				content: {
					content: allArticle, //传递的组件对象
					parent: this,//当前的vue对象
					data: {
						articleType: item.articleType
					}//props
				},
				area: ['900px', '650px'],
				title: item.title,
				cancel: () => {//关闭事件
					//alert('关闭iframe');
				},
				maxmin: true
			});
			
			/* this.$router.push({
				 path: "/allArticle",
				 query: {articleType},
			 });*/
		},
		//点击文章
		onArticle(item) {
			
			let address = this.urlAbsolute(`/experience/index.html#/articleDetail?articleId=${item.articleId}&articleType=${item.articleType}&path=1`)
			
			openWeb(address,item.articleTypeName,1);
			
			return;
			
			
			this.$layer.iframe({
				content: {
					content: articleDetail, //传递的组件对象
					parent: this,//当前的vue对象
					data: {
						newsId: item.articleId,
						articleType: item.articleType
					}//props
				},
				area: ['900px','650px'],
				title: item.articleTypeName,
				cancel: () => {//关闭事件
					//alert('关闭iframe');
				},
				maxmin: true,
				scrollbar: false,
			});
			
		},
		//点击视频
		onVideo(item) {
			
			let url = '';
			if (/inmuu/g.test(item.playbackLink)) {
				url = item.playbackLink;
			} else {
				let token = localStorage.getItem('token') || '';
				url = item.playbackLink + '&token=' + token;
			}
			
			if (item.playbackLink) {
				windowOpen(url, item.subject);
			} else {
				this.$layer.iframe({
					content: {
						content: videoTtv, //传递的组件对象
						parent: this,//当前的vue对象
						data: {
							configId: item.configId,
							videoId: item.videoId
						}//props
					},
					area: ['900px', '650px'],
					title: item.channelName,
					maxmin: true,
					shade: true,
				});
			}
		},
		//点击视频分类
		onVideoGroup(item) {
			
			let address = this.urlAbsolute(`/experience/index.html#/allVideo?configId=${item.configId}`);
			openWeb(address,item.channelName,1);
			return;
			
			
			this.$layer.iframe({
				content: {
					content: allVideo, //传递的组件对象
					parent: this,//当前的vue对象
					data: {
						configId: item.configId
					}//props
				},
				area: ['900px', '650px'],
				title: item.channelName,
				maxmin: true,
				shade: true,
			});
			/*this.$router.push({
				path: "/allVideo",
				query: {configId:obj.configId,videoId:obj.videoId},
			});*/
		},
		//点击打开新页面
		onClick(item) {
			if (item.link != undefined && item.link != '') {
				windowOpen(item.link);
			}else if (item.newLink != undefined && item.newLink != '') {
				windowOpen(item.newLink);
			}
		},
		//往期更多视频
		onVideoList(productId = '', centralToken = '') {
			let address = `/experience/index.html#/videoList?productId=${productId}&token=${centralToken}`;
			openWeb(this.urlAbsolute(address), '往期视频', 0);
		},
		//等比率缩放页面
		ratioStyle(val) {
			
			let winWidth = document.body.clientWidth;
			if (val.includes('px')) {
				if (winWidth > 1366) {
					let scalingRatio = winWidth / 1920;
					return scalingRatio * parseInt(val) + 'px';
				} else {
					return val;
				}
			} else {
				return val;
			}
		},
		//关闭左侧广告 5分钟后显示
		onClose() {
			this.show = false;
			setTimeout(() => {
				this.show = true;
			}, 300000)
		},
		//打开提示框
		openLayer(title = '', str = '') {
			this.$layer.iframe({
				content: {
					content: msg,
					parent: this,
					data: {
						msg: str
					}
				},
				area: ['400px', '140px'],
				title: title,
				maxmin: false,
				shade: true,
				cancel: () => { //关闭弹窗事件
				}
			});
		}
	}
}

export default mixin;